{extends file="./main.tpl"}
{block name=head}
<script type="text/javascript">
$(document).ready(function()
{
  setVoucherNo();
  $(".accountCr").blur(function()
  {
    if($(".accountCr:last").val() != '' && $(".accountCr:last").val() > 0)
    {
      $("#one1").clone(true).appendTo("#mainDiv1")
      .find('input[type="text"]').val('').end()
      .find('select[option=""]').val('');
    }
  });
  $(".accountDr").blur(function()
  {
    if($(".accountDr:last").val() != '' && $(".accountDr:last").val() > 0)
    {
      $("#one2").clone(true).appendTo("#mainDiv2")
      .find('input[type="text"]').val('').end()
      .find('select[option=""]').val('');
    }
  });
});
function setVoucherNo()
{
  var dayExtra   = $('#fromDateDay').val();
  var monthExtra = $('#fromDateMonth').val();
  var yearExtra  = $('#fromDateYear').val();
  var voucherType = $('.voucherType').val();
	var fullDate = yearExtra+'-'+monthExtra+'-'+dayExtra;
	var dataString = "fullDate=" + fullDate + "&voucherType=" + voucherType;
  $.ajax(
  {
    type: "GET",
    url: "setVoucherNo.php",
    data: dataString,
    success:function(data)
    {
      $('#getVoucherNo').val(data);
    }
  });
}
function newWindow()
{
	if($('#payment').val() == 'Payment' || $('#payment').val() == 'Receipt')
	{
		window.location.replace('transaction.php?payment='+$('#payment').val(), '_self');
	}
}
function setAmountTotal()
{
  var totalAmountCr = 0;
  var totalAmountDr = 0;
  
  $('.amountCr').each(function(i)
  {
    amountCr = $(this).val();
    if(!isNaN(amountCr))
    {
      totalAmountCr += Number(amountCr);
    }
  });
  $('#totalAmountCr').val(totalAmountCr.toFixed(2));
  $('.amountDr').each(function(i)
  {
    amountDr = $(this).val();
    if(!isNaN(amountDr))
    {
      totalAmountDr += Number(amountDr);
    }
  });
  $('#totalAmountDr').val(totalAmountDr.toFixed(2));
}

function submitRecord()
{
	var totalAmountDr = $('#totalAmountDr').val();
	var totalAmountCr = $('#totalAmountCr').val();
	
  if(totalAmountDr == totalAmountCr && totalAmountDr > 0 && totalAmountCr > 0)
  {
	  return confirm('DO You Want To Submit !!!!!');
  }
  else
  {
  	alert('Your Account is not Proper !!!!!');
  	return false;
  }
}
</script>
{/block}
{block name=body}
<form action="{$smarty.server.PHP_SELF}" method="POST" onsubmit="return submitRecord();">
<table cellpadding="2" cellspacing="0" border="1" align="center">
  <tr>
    <td colspan="4" align="center" style="background:#EBF5FF;">
    	<h1><font size="5px">Credit/Debit</font></h1>
    </td>
  </tr>
  <tr>
    <th>Voucher</th>
    <th>Date</th>
    <th>Voucher No.</th>
  </tr>
  <tr>
    <td>
    	<select name="voucherType" id="payment" class="voucherType" onchange="newWindow(); setVoucherNo();" AUTOFOCUS  required >
      	<option value="">-- Select Voucher --</option>
      	{html_options values=$paymentValuesArr output=$paymentOutputArr selected=$payment}
      </select>
    </td>
    <td onchange="setVoucherNo();">
      {html_select_date day_extra="id=\"fromDateDay\"" month_extra="id=\"fromDateMonth\"" year_extra="id=\"fromDateYear\"" prefix='transDate' field_order="DmY" month_format="%m" start_year='-5' end_year='+5' day_value_format="%02d"}
    </td>
    <td><input type="text" name="voucherNo" id="getVoucherNo" size="15" READONLY /></td>
  </tr>
</table>
</br></br></br>
<table cellpadding="2" cellspacing="0" border="1" align="center">
  <tr>
    <td valign="top">
	    <table cellpadding="2" cellspacing="0" border="1">
		    <tbody id="mainDiv1">
		    <tr>
		      <td colspan="2" align="center" style="background:#EBF5FF;">
		      	<h1><font size="5px">Credit Account</font></h1>
		      </td>
		    </tr>
		    <tr>
		      <th>Account Name</th>
		      <th>Amount</th>
		    </tr>
		    <tr  id="one1" class="amtRow1">
		      <td align="center">
		        <select name="crAccountId[]" class="accountCr">
		        	<option value="0">-- select Account --</option>
		        	{html_options values=$accArray.accountId output=$accArray.accountName}
		        </select>
		      </td>
		      <td align="center">
		        <input type="text" name="crAmount[]" class="amountCr textAlignRight twoToFixed" size="15" onkeyup="setAmountTotal();" />
		      </td>
		    </tr>
		    </tbody>
			  <tr>
			    <th colspan="1">Total</th>
			    <td align="center"><input type="text" name="totalAmountCr" id="totalAmountCr" class="textAlignRight" size="15" /></td>
			  </tr>
	    </table>
    </td>
    <td valign="top">
	    <table cellpadding="2" cellspacing="0" border="1">
	      <tbody id="mainDiv2">
	      <tr>
	        <td colspan="2" align="center" style="background:#EBF5FF;">
	      	  <h1><font size="5px">Debit Account</font></h1>
	        </td>
		    </tr>
		    <tr>
		      <th>Account Name</th>
		      <th>Amount</th>
		    </tr>
		    <tr  id="one2" class="amtRow2">
		      <td align="center">
		        <select name="drAccountId[]" class="accountDr">
		        	<option value="0">-- select Account --</option>
		        	{html_options values=$accArray.accountId output=$accArray.accountName}
		        </select>
		      </td>
		      <td align="center">
		        <input type="text" name="drAmount[]" class="amountDr textAlignRight twoToFixed" size="15" onkeyup="setAmountTotal();" />
		      </td>
		    </tr>
		    </tbody>
			  <tr>
			    <th colspan="1">Total</th>
			    <td align="center"><input type="text" name="totalAmountDr" id="totalAmountDr" class="textAlignRight" size="15" /></td>
			  </tr>
			</table>
		</td>
  </tr>
  <tr>
  	<td colspan="4">
      <input type="submit" name="submitBtn" value="Save" />
    </td>
  </tr>
</table>
</form> 
{/block}